import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout/index.vue'

const constantRoutes = [
  {
    path: '/errorpage',
    component: () => import('@/views/errorpage/errorpage.vue'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    children: [{
      path: '/',
      name: 'index',
      component: () => import('@/views/index/index.vue'),
      meta: { title: '主页', icon: 'dashboard'}
    },{
      path: 'index',
      name: 'index2',
      component: () => import('@/views/index/index.vue'),
      meta: { title: '主页', icon: 'dashboard'}
    }]

  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/errorpage', hidden: true }
]


const createRouter = () => new Router({
  mode: 'history',
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router